package com.yyk.yiliao.ui.mine.activity;


import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.adapter.CommonTabPagerAdapter;

import com.yyk.yiliao.ui.mine.fragment.Registraion_Fragment;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * mine---挂号记录   https://blog.csdn.net/huangbin123/article/details/78922394
 */
public class Registration_Activity extends BaseActivity {

    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.mRegistration_vp)
    ViewPager mRegistrationVp;

    private CommonTabPagerAdapter tablyoutAdapter;


    @Override
    public int getLayoutId() {
        return R.layout.activity_registration;
    }

    @Override

    public void initView() {
        initToolbar();
        initTablyout();

        /**
         *
         * 如果要实现跳转某个指定的 fragment可以这样写
         */

//
//        Intent intentOne = new Intent(getActivity(), Registration_Activity.class);
//        intentOne.putExtra("tab_id", 1);
//        startActivity(intentOne);
//        int tab_id = getIntent().getIntExtra("tab_id", 0);
//        if (tab_id == 1) {
//            mRegistrationVp.setCurrentItem(0);
//        } else if (tab_id == 2) {
//            mRegistrationVp.setCurrentItem(1);
//        } else if (tab_id == 3) {
//            mRegistrationVp.setCurrentItem(2);
//        } else {
//            mRegistrationVp.setCurrentItem(3);
//        }
    }

    private void initToolbar() {
        setBackArrow();
        setTitle("挂号记录");
    }

    @Override
    public void initData() {

    }

    private String[] title = {"未使用", "已使用", "已过期", "已退号"};
    private int[] postion = {1, 2, 3, 4};
    private List<String> titleList = new ArrayList<>();
    private List<Integer> postionList = new ArrayList<>();

    /**
     * 初始化tablyout
     */
    private void initTablyout() {
        for (int i = 0; i < title.length; i++) {
            titleList.add(title[i]);
            postionList.add(postion[i]);
        }
        //设置TabLayout点击事件
        tablyoutAdapter = new CommonTabPagerAdapter(getSupportFragmentManager()
                , titleList.size(), titleList, this);
        tablyoutAdapter.setListener(new CommonTabPagerAdapter.TabPagerListener() {
            @Override
            public Fragment getFragment(int position) {
                Registraion_Fragment fragment = Registraion_Fragment.newInstance(position);
                Bundle bundle = new Bundle();
                bundle.putString(Registraion_Fragment.ARGS_PAGE, postionList.get(position) + "");
                fragment.setArguments(bundle);
                return fragment;
            }
        });
        mRegistrationVp.setAdapter(tablyoutAdapter);
        tabLayout.setupWithViewPager(mRegistrationVp);
        mRegistrationVp.setCurrentItem(0);

    }
}
